home *** CD-ROM | disk | FTP | other *** search
/ Network Support Library / RoseWare - Network Support Library.iso / apidev / ndr4.exe / CASELA.TXT next >
Text File  |  1994-01-18  |  9KB  |  246 lines

  1. /****************************************************************************
  2. The following code was taken from the Network Developer's Resource, published
  3. by RoseWare.  All contents are Copyright (c) 1993, RoseWare.  All Rights
  4. Reserved.
  5.  
  6. This material is made available as a service for subscribers of the Network
  7. Developer's Resource.  This material is not public domain.  Simply put, if you
  8. are not a subscriber of the Network Developer's Resource, you are using this
  9. material illegally.  
  10.  
  11. Those interested in subscribing should contact RoseWare via:
  12.  
  13. CompuServe:    76711,110
  14. Internet:      76711.110@compuserve.com
  15. Phone:         (704) 258-9166
  16. Fax:           (704) 258-9374
  17. BBS:           (704) 258-8675
  18. US Mail:       P.O. Box 8564
  19.            Asheville, NC  28814-8564    
  20.  
  21. Also see the file SUBSCRIB.TXT in this ZIP file...
  22. ****************************************************************************/
  23.  
  24. Developing NetWare Utilities Fast
  25.  
  26. The Visual Basic installed base has grown tremendously since its introduction as a programming tool. It has quickly become the development platform of choice for a wide range of applications. Writing network utilities and network aware applications using Visual Basic for Windows is a natural. With just a little help from your favorite C compiler, the power of NetWare could easily be at your fingertips.
  27.  
  28. There have been a number of articles on calling Novells own DLLs from Visual Basic but, if you want to get maximum control, flexibility and support for networks other than NetWare, you have two options:
  29.  
  30.     Write your own DLLs.
  31.  
  32.     Buy an add-on network package with support for multiple networks, source        code, documentation and demonstration programs.
  33.  
  34. If you are going to write your own DLLs, you must first decide on a C compiler. I like the Microsoft Visual C/C++ one. It is a high quality tool and comes with an excellent debugger, CodeView for Windows. Also, documentation on interfacing DLLs with this compiler are available from Microsoft on CompuServe. Once youve decided on the tools, you are ready to write some code. My recommendation is to start simple. Writing high quality DLLs can get real complicated in the blink of an eye.
  35.  
  36. I have prepared a demonstration program for this article which is simple and useful. It is a program to check the security equivalences of a Bindery Object.
  37.  
  38.  
  39. Microsoft Visual C/C++ .DEF code:
  40. LIBRARY                 SECEQUIV
  41. EXETYPE                 WINDOWS
  42. DESCRIPTION             'Security Equivalence Demo'
  43. CODE                    PRELOAD MOVEABLE DISCARDABLE
  44. DATA                    PRELOAD MOVEABLE SINGLE
  45. HEAPSIZE                8192
  46. EXPORTS
  47.             WEP PRIVATE
  48.  
  49.  
  50. Microsoft Visual C/C++ C DLL code:
  51.  
  52. // some includes
  53. #include <dos.h>
  54. #include <fcntl.h>
  55. #include <io.h>
  56. #include <malloc.h>
  57. #include <memory.h>
  58. #include <share.h>
  59. #include <stdio.h>
  60. #include <stdlib.h>
  61. #include <string.h>
  62. #include <sys\types.h>
  63. #include <sys\stat.h>
  64. #include <windows.h>
  65.  
  66. // Read property value request structure
  67. struct readPropertyValueRequest
  68. {
  69.     WORD    length;
  70.     BYTE    req_no;
  71.     WORD    object_type;
  72.     BYTE    object_name_length;
  73.     BYTE    object_name[48];
  74.     BYTE    segment_number;
  75.     BYTE    property_name_length;
  76.     BYTE    property_name[16];
  77. };
  78.  
  79. // Read property value reply structure
  80. struct readPropertyValueReply
  81. {
  82.     WORD    length;
  83.     BYTE    property_value[128];
  84.     BYTE    more_segments;
  85.     BYTE    property_flags;
  86. };
  87.  
  88. // return structure for Visual Basic
  89. // we just want to return the Bindery Object IDs
  90. // found in the 128 Byte property_value element
  91. typedef struct
  92. {
  93.     LONG object_ID[31]; 
  94. } gSecEquiv;
  95.  
  96. // Returns: completion code, array of Bindery Object IDs
  97. // Accepts: Bindery Object Name 
  98. int FAR PASCAL _export NW_SecurityEquivalence(char far *cName,
  99.     struct gSecEquiv *SEquiv) 
  100. {
  101.     struct readPropertyValueRequest request;
  102.     struct readPropertyValueReply           reply;
  103.     int i=0,ccode;
  104.     HINSTANCE hNetWareDrv;
  105.     LONG object=0, objectID[31];
  106.     long (FAR PASCAL *NetWareRequest) (void);
  107.  
  108.     NetWareRequest = NULL;
  109.   
  110.     // See if the NETWARE.DRV module is loaded
  111.     // and attempt to obtain a handle.
  112.     hNetWareDrv = GetModuleHandle("NETWARE");
  113.   
  114.     // If there is a handle, perform the function.
  115.     if(hNetWareDrv > HINSTANCE_ERROR)
  116.     {
  117.         // Initialize the request and reply structures.
  118.         _fmemset(&request, 0x00, sizeof(request));
  119.         _fmemset(&reply, 0x00, sizeof(reply));
  120.  
  121.         // Put the Bindery Object Name into the request structure.
  122.         _fstrcpy(request.object_name, cName);
  123.   
  124.         // Obtain the Bindery Object Names length.                                      request.object_name_length=sizeof(request.object_name);
  125.  
  126.         // Its a Bindery Object of type User.
  127.         request.object_type=0x0100;
  128.  
  129.         // The first call needs a segment number of 1.
  130.         request.segment_number=1;
  131.  
  132.         // The property name is SECURITY_EQUALS
  133.         _fstrcpy(request.property_name, "SECURITY_EQUALS");
  134.  
  135.         // Obtain the size of the property name.
  136.         request.property_name_length=sizeof(request.property_name);
  137.         
  138.         // Get the size of the request structure.
  139.         request.length=sizeof(request)-2;
  140.         
  141.         // The function number for this NetWare API is 0x3D
  142.         request.req_no=0x3D;
  143.  
  144.         // Get the size of the return structure.
  145.         reply.length=sizeof(reply)-2;
  146.  
  147.         // Make the actual function call and
  148.         // write some code of your own to evaluate 
  149.         // the return code.
  150.         ccode = NetWareCall(0xE3, (LPSTR)&request, (LPSTR)&reply);
  151.  
  152.         // Go through the 128 Byte reply.property_value element                         // looking for Bindery Object IDs.
  153.         for (i=0; i<32; i++)
  154.         {
  155.             // Each Bindery Object ID is 4 bytes.
  156.             object = *((LONG *)(reply.property_value + (I*4)));
  157.  
  158.             // Get the data into a temporary array of LONGs.
  159.             objectID[i] = object;
  160.             object = 0;
  161.         }       
  162.  
  163.         // Move the data into our Visual Basic return structure.
  164.         _fmemmove(SEquiv, &objectID, sizeof(gSecEquiv));
  165.     
  166.         return ccode;
  167.   }
  168.   else
  169.   {
  170.     // the NETWARE.DRV DLL is not loaded
  171.     // call the error function.
  172.     NetWareDriverError();
  173.   }
  174. };
  175.  
  176. // This function does the actual call to the NetWare shell.
  177. WORD NetWareCall(BYTE function, LPSTR request, LPSTR reply)
  178. {
  179.     // Some of this code could be found in previous issues of NDR
  180.     // You may want to consult those back issues for some   
  181.     // understanding of this function if it is not obvious.
  182.     BYTE ccode;
  183.     HINSTANCE hNetWareDrv;
  184.     long (FAR PASCAL *NetWareRequest) (void);
  185.     long (FAR PASCAL *NetWareRequest2) (void);
  186.  
  187.     NetWareRequest = NULL;
  188.       
  189.     hNetWareDrv = GetModuleHandle("NETWARE");
  190.   
  191.     (FARPROC) NetWareRequest = GetProcAddress(hNetWareDrv,                          "NetWareRequest");
  192.         
  193.     NetWareRequest2 = NetWareRequest;
  194.         
  195.     _asm xor        al,al
  196.     _asm push       ds
  197.     _asm push       es
  198.     _asm mov        ah,function
  199.     _asm lds        si,request
  200.     _asm les        di,reply
  201.     NetWareRequest2();
  202.     _asm pop        es
  203.     _asm pop        ds
  204.     _asm xor        ah,ah
  205.     _asm mov        ccode,al
  206.  
  207.     return (WORD)ccode;
  208. };
  209.  
  210. // If the module was not loaded, this function gets called.
  211. void NetWareDriverError(void)
  212. {
  213.     // Change this to an error message of your choice.
  214.     // You could remove the message box code and return a number
  215.     MessageBox(NULL,"NETWARE.DRV not loaded. Check Windows Setup             and/or NetWare Shell", "FATAL ERROR",MB_ICONSTOP | MB_OK);
  216. };
  217.  
  218.  
  219. Microsoft Visual Basic for Windows 3.0 code:
  220.  
  221. // Dimension an array of Longs to receive the return from your DLL.
  222. Type ObjectIDs
  223.     object_ID(31) As Long
  224. End Type
  225.  
  226. // This is the function declaration.
  227. Declare Function NW_SecurityEquivalence% Lib "SECEQUIV.DLL" (ByVal _ 
  228.     Name$, IDs As ObjectIDs)
  229.  
  230. // Dimension an array of type ObjectIDs
  231. Dim NWIDs As ObjectIDs
  232.     
  233. // Call the function passing a Bindery Object Name
  234. ccode% = NW_SecurityEquivalence("GUEST", NWIDs)
  235.  
  236. // Look at the first Bindery Object ID returned
  237. // and evaluate it. If it is a 0 then there are
  238. // no Bindery Object IDs or this is the last one.
  239. Label1.Caption = Hex$(NW_SwapLong(NWIDs.object_ID(0)))
  240.  
  241. You can enhance this program by using the supervisor Bindery Object ID and comparing it to the returned values to check for supervisor equivalence. Also, in the basic program you could return the non-zero values to a list box for selection and use into another function. Remember that the values returned are in Hi-Lo format. 
  242.  
  243. Using Visual Basic for Windows 3.0 with C may just give you the best of all worlds.
  244.  
  245. Stephen Casella is the author of NetPak Professional, a multi-network add-on library for Visual Basic for Windows and Visual Basic for MS-DOS. NetPak Professional supports, NetWare 2.X, 3.X, 4.X and Windows for Workgroups and is sold by Crescent Software, Inc. in Ridgefield, Connecticut. It can be ordered by calling (203-438-5300).
  246.